﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace SpyApp.Helpers
{
    public static class UrlHelperExtensions
    {
        #region Url Helper
        /// <summary>
        /// Thêm tham số trong route hiện tại (Url.)
        /// </summary>
        public static HtmlString _AddRouteValues(this UrlHelper urlHelper, object routeValues)
        {
            //ViewContext.ParentActionViewContext.RouteData.Values["action"] // get action / controller
            RouteValueDictionary newRoute = new RouteValueDictionary(routeValues); // Convert new route values to a dictionary
            var current = urlHelper.RequestContext.RouteData.Values; // Get the route data of the current Url
            // Merge the new values INTO the current values, overwriting any existing values/querystrings
            foreach (var item in newRoute)
            {
                current[item.Key] = item.Value;
            }
            var newUrl = urlHelper.RouteUrl(current); // Generate the new Url
            return new HtmlString(newUrl);
        }

        #endregion

    }
}